package com.xyht.medicine_management_system.modules.medicine.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.medicine.entity.req.MmsMedicineRecommendAddListReq;
import com.xyht.medicine_management_system.modules.medicine.entity.req.MmsMedicineRecommendDeletedReq;
import com.xyht.medicine_management_system.modules.medicine.service.MmsMedicineRecommendService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 推荐药品 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-04
 */
@RestController
@SecretBody
@RequestMapping("/medicine/recommend")
public class MmsMedicineRecommendController {

    @Resource
    private MmsMedicineRecommendService medicineRecommendService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加推荐药品")
    @PostMapping("/add")
    public ResponseResult addMedicineRecommend(@RequestBody MmsMedicineRecommendAddListReq addReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return medicineRecommendService.addMedicineRecommend(addReq,userId);
    }

    @ApiModelProperty("删除推荐药品")
    @PostMapping("/deleted")
    public ResponseResult deletedMedicineRecommend(@RequestBody MmsMedicineRecommendDeletedReq deletedReq){
        return medicineRecommendService.deletedMedicineRecommend(deletedReq);
    }

    @ApiModelProperty("查看推荐药品列表")
    @GetMapping("/list")
    @RequestPass
    public ResponseResult getMedicineRecommendList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "name", required = false) String name,
                                                   @RequestParam(value = "isOn", required = false) Integer isOn,
                                                   HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdOrNullByRequest(request);
        return medicineRecommendService.getMedicineRecommendList(pageNum,pageSize,name,isOn,userId);
    }

}

